/*
 * @Description: 城市和产业发展 js
 * @Author: zhangchenna
 * @Date: 2019-02-25 17:06:37
 * @LastEditTime: 2019-04-23 22:05:43
 */
import '../../style/kmg/index.scss';
import '../../utils/header';

let nav = document.querySelectorAll('.industry-left li'),
    list = document.querySelectorAll('.industry-right');

function getQueryString(name) {
    let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i'),
        r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

let index = getQueryString('index');

if (index !== null) {
    nav[index - 1].classList.add('industry-active');
    list[index - 1].classList.remove('mit-hide');
} else {
    nav[0].classList.add('industry-active');
    list[0].classList.remove('mit-hide');
}

for (let i = 0; i < nav.length; i++) {
    nav[i].addEventListener(
        'click',
        function() {
            nav.forEach(item => {
                if (item.className.includes('industry-active')) {
                    item.classList.remove('industry-active');
                }
            });
            list.forEach(item => {
                if (!item.className.includes('mit-hide')) {
                    item.classList.add('mit-hide');
                }
            });
            list[i].classList.remove('mit-hide');
            this.classList.add('industry-active');
        },
        false
    );
}
